package istar.impl;

import java.io.Serializable;

import istar.IActor;
import istar.IDependency;
import istar.IElement;

public class Dependency implements IDependency, Serializable{

	protected String name;
	protected IElement dependendum;
	protected int type;
	protected IActor depender;
	protected IActor dependee;
	protected IElement dependerElement;
	protected IElement dependeeElement;
	
	
	
	@Override
	public Object clone() throws CloneNotSupportedException {
		Dependency newClone = (Dependency)super.clone();
		newClone.dependee = this.dependee;
		newClone.depender = this.depender;
		newClone.dependendum = this.dependendum;
		newClone.dependeeElement = this.dependeeElement;
		newClone.dependerElement = this.dependerElement;
		return newClone;
	}

	public Dependency(String name, IElement dependum,  
							  IActor depender, IActor dependee){
		this.name = name;
		this.dependendum = dependum;
		this.dependee = dependee;
		dependee.getDependeeElements().add(dependum);
		this.depender = depender;
		depender.getDependerElements().add(dependum);
		dependum.getDependencies().add(this);
	}
	
	public Dependency(String name, IElement dependum, 
					IActor depender, IElement dependeeElement){
		this.name = name;
		this.dependendum = dependum;
		this.dependeeElement = dependeeElement;

		IActor owner = dependeeElement.getOwner();
		dependee = owner;
		dependee.getDependeeElements().add(dependum);

		this.depender = depender;
		depender.getDependerElements().add(dependum);

		dependum.getDependencies().add(this);
	}
	
	public Dependency(String name, IElement dependum, 
			  IElement dependerElement, 
			  IActor dependee){
		this.name = name;
		this.dependendum = dependum;
		this.dependerElement = dependerElement;

		IActor owner = dependerElement.getOwner();
		depender = owner;
		depender.getDependerElements().add(dependum);

		this.dependee = dependee;
		dependee.getDependerElements().add(dependum);
	
		dependum.getDependencies().add(this);
}

	public Dependency(String name, IElement dependum, 
							  IElement dependerElement, 
							  IElement dependeeElement){
		this.name = name;
		this.dependendum = dependum;
		this.dependeeElement = dependeeElement;
		this.dependerElement = dependerElement;

		IActor owner = dependeeElement.getOwner();
		dependee = owner;
		if (!owner.getDependeeElements().contains(dependum))
			owner.getDependeeElements().add(dependum);

		owner = dependerElement.getOwner();
		depender = owner;
		if (!owner.getDependerElements().contains(dependum))
			owner.getDependerElements().add(dependum);
		
		dependum.getDependencies().add(this);
	}
	
	public IElement getDependerElement() {
		return dependerElement;
	}


	public IElement getDependeeElement() {
		return dependeeElement;
	}

	
	public IActor getDepender() {
		return depender;
	}


	public void setDepender(IActor depender) {
		this.depender = depender;
	}


	public IActor getDependee() {
		return dependee;
	}


	public void setDependee(IActor dependee) {
		this.dependee = dependee;
	}


	@Override
	public IElement getDependum() {
		return dependendum;
	}

	@Override
	public String getName() {
		return name;
	}

	@Override
	public int getType() {
		return type;
	}

	@Override
	public void setType(int value) {
		this.type = value;
	}
	
	@Override
	public void setDependum(IElement value) {
		this.dependendum = value;
	}

	@Override
	public void setName(String value) {
		this.name = value;
	}


	
}
